#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int N=2e5+10;
int n,p=1;
int a[N],b[N];
void work1()
{
	while(p)
	{
		int t=-1;
		p=0;
		for(int i=1; i<=n; ++i)
		{
			if(b[i]!=-1&&b[i]!=t)
			{
				t=b[i];
				b[i]=-1;
				p=1;
				printf("%d ",i);
			}
		}
		printf("\n");
	}
}
int g,tot,t;
int f[N],ff[N];
int w[N],ww[N];
vector<int>ans[N];
int main()
{
	freopen("fruit.in","r",stdin);
	freopen("fruit.out","w",stdout);
	scanf("%d",&n);
	for(int i=1; i<=n; ++i)
		scanf("%d",&a[i]),b[i]=a[i];
	if(n<=20000)
	{
	work1();
	return 0;
	}
	a[n+1]=2;
	g=0;
	a[0]=a[1],a[n+1]=!a[n];
	for(int i=1; i<=n; ++i)
	{
		if(a[i]==a[i-1])
			++g;
		w[i]=g;
		if(a[i]!=a[i+1])
		{
			f[++tot]=g;
			g=1;
		}
	}
	//for(int i=1; i<=tot; ++i)
	//{
	//	cout<<f[i]<<' ';
	//}
	//cout<<endl;
	t=1;
	g=0;
	int maxx=0;
	for(int i=1; i<=n; ++i)
	{
		if(a[i]==a[i-1])
			++g;
		if(g>f[t-1])
		w[i]+=ww[t];
		ww[t]=max(0,f[t-2]-f[t-1]+ww[t-2]);
				//cout<<t<<' '<<ww[t]<<endl;
		if(a[i]!=a[i+1])
		{
			++t;
			g=1;
		}
		//cout<<t<<' '<<ww[t]<<endl;
		maxx=max(maxx,w[i]);
	}
	//cout<<endl<<endl;
	for(int i=1; i<=n; ++i)
		ans[w[i]].push_back(i);
	for(int i=1; i<=maxx; ++i)
	{
		for(int j=0; j<ans[i].size(); ++j)
			printf("%d ",ans[i][j]);
		printf("\n");
	}
	return 0;
}
